package com.xyh.student.service.impl;

import com.xyh.student.dao.BanjiDao;
import com.xyh.student.entity.Banji;
import com.xyh.student.entity.ResponseData;
import com.xyh.student.service.BanjiService;
import com.xyh.student.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BanjiServiceImpl implements BanjiService {
    @Autowired
    private BanjiDao banjiDao;

    @Override
    public ResponseData getBanjis() {
        try{
            List<Banji> banjis=banjiDao.getBanjis();
            return new ResponseData("0","请求成功",banjis);
        }catch (Exception e){
            System.out.println(e);
            return new ResponseData("888","请求失败");
        }
    }

    @Override
    public ResponseData update(Banji banji) {
        try{
            this.banjiDao.update(banji);
            List<Banji> banjis=banjiDao.getBanjis();
            return new ResponseData("0","请求成功",banjis);
        }catch (Exception e){
            System.out.println(e);
            return new ResponseData("888","请求失败");
        }

    }

    @Override
    public ResponseData insert(Banji banji) {
        try{
            this.banjiDao.insert(banji);
            List<Banji> banjis=banjiDao.getBanjis();
            return new ResponseData("0","请求成功",banjis);
        }catch (Exception e){
            System.out.println(e);
            return new ResponseData("888","请求失败");
        }
    }

    @Override
    public ResponseData deleteByName(String name) {
        try{
            this.banjiDao.deleteByName(name);
            List<Banji> banjis=banjiDao.getBanjis();
            return new ResponseData("0","请求成功",banjis);
        }catch (Exception e){
            System.out.println(e);
            return new ResponseData("888","请求失败");
        }
    }

    @Override
    public ResponseData deletesByIds(String[] ids) {
        try{
            this.banjiDao.deletesByIds(ids);
            List<Banji> banjis=banjiDao.getBanjis();
            return new ResponseData("0","请求成功",banjis);
        }catch (Exception e){
            System.out.println(e);
            return new ResponseData("888","请求失败");
        }
    }

    @Override
    public ResponseData numberOfBanji() {
        try{
            int i=this.banjiDao.numberOfBanji();
            return new ResponseData("0","请求成功",i);
        }catch (Exception e){
            System.out.println(e);
            return new ResponseData("888","请求失败");
        }
    }

    @Override
    public ResponseData queryByName(String name) {
        try{
            name = "%"+name+"%";
            List<Banji> banjis= banjiDao.queryByName(name);
            return new ResponseData("0","请求成功",banjis);
        }catch (Exception e){
            System.out.println(e);
            return new ResponseData("888","请求失败");
        }
    }

    @Override
    public ResponseData findByPage(Integer page, Integer size) {
        try{
            List<Banji> banjis=this.banjiDao.findByPage((page-1)*size,size);
            return new ResponseData("0","请求成功",banjis);
        }catch (Exception e){
            System.out.println(e);
            return new ResponseData("888","请求失败");
        }
    }

    @Override
    public ResponseData deleteById(Integer cid) {
        try{
            this.banjiDao.deleteById(cid);
            List<Banji> banjis=banjiDao.getBanjis();
            return new ResponseData("0","请求成功",banjis);
        }catch (Exception e){
            System.out.println(e);
            return new ResponseData("888","请求失败");
        }
    }

    @Override
    public ResponseData deletesById(int[] cids) {
        try{
            this.banjiDao.deletesById(cids);
            List<Banji> banjis=banjiDao.getBanjis();
            return new ResponseData("0","请求成功",banjis);
        }catch (Exception e){
            System.out.println(e);
            return new ResponseData("888","请求失败");
        }
    }
//    @Override
//    public ResponseData findAllBanjis() {
//        try{
//            List<Banji> banjis=banjiDao.queryAllBanjis();
//            return new ResponseData("0","请求成功",banjis);
//        }catch (Exception e){
//            System.out.println(e);
//            return new ResponseData("888","请求失败");
//        }
//    }
//
//    @Override
//    public ResponseData queryStudentByBanjiId(Integer id) {
//        try{
//            List<Student> students=banjiDao.queryStudentByBanjiId(id);
//            return new ResponseData("0","请求成功",students);
//        }catch (Exception e){
//            System.out.println(e);
//            return new ResponseData("888","请求失败");
//        }
//    }
//
//    @Override
//    public ResponseData insertBanji(Banji banji) {
//        String name=banji.getName();
//        String brief=banji.getBrief();
//        String manager=banji.getManager();
//        Date date=banji.getTime();
//        if(StringUtil.isNull(name)){
//            return new ResponseData("888","班级名为空");
//        }
//        if(StringUtil.isNull(brief)){
//            return new ResponseData("888","班级简介为空");
//        }
//        if(StringUtil.isNull(manager)){
//            return new ResponseData("888","班主任为空");
//        }
//        if(date==null){
//            return new ResponseData("888","时间为空");
//        }
//        try{
//            Banji queryBanji=banjiDao.queryBanjiByBanjiName(name);
//            if(queryBanji!=null)
//                return new ResponseData("888","该班级已经存在");
//            int i=banjiDao.insert(banji);
//            return new ResponseData("0","请求成功",i);
//        }catch (Exception e){
//            System.out.println(e);
//            return new ResponseData("888","请求失败");
//        }
//    }
//
//    @Override
//    public ResponseData deleteById(Integer id) {
//        try{
//            int i=banjiDao.deleteById(id);
//            return new ResponseData("0","请求成功",i);
//        }catch (Exception e){
//            System.out.println(e);
//            return new ResponseData("888","请求失败");
//        }
//    }
//
//    @Override
//    public ResponseData deletes(int[] ids) {
//        try{
//            int i=banjiDao.deletes(ids);
//            return new ResponseData("0","请求成功",i);
//        }catch (Exception e){
//            System.out.println(e);
//            return new ResponseData("888","请求失败");
//        }
//    }
//
//    @Override
//    public ResponseData update(Banji banji) {
//        try{
//            int i=banjiDao.update(banji);
//            return new ResponseData("0","请求成功",i);
//        }catch (Exception e){
//            System.out.println(e);
//            return new ResponseData("888","请求失败");
//        }
//    }
//
//    @Override
//    public List<Map<String, Object>> getBanjisForVue() {
//        return this.banjiDao.getBanjisForVue();
//    }
//
//    @Override
//    public ResponseData numberOfBanji() {
//        try{
//            int i=banjiDao.numberOfBanji();
//            return new ResponseData("0","请求成功",i);
//        }catch (Exception e){
//            System.out.println(e);
//            return new ResponseData("888","请求失败");
//        }
//    }
//



}
